# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： alarm
Description :
Author : 'li'
date： 1/15/2024
-------------------------------------------------
Change Activity:
1/15/2024:
-------------------------------------------------
"""
# from types import NoneType
#
# from ll.common.string_util import get_string_md5
#
#
# class Alarm:
#     def __init__(
#             self,
#             timestamp=None,
#             ip=None,
#             hostname=None,
#             severity=None,
#             alarm_type=None,  # 'alarm,recovery'
#             alarm_info=None,
#             note=None,
#             recovery=False,
#             recovery_time=None,
#             manager_ip=None,
#             manager_port=None,
#             alarm_source=None
#     ):
#         assert alarm_type in [None, 'alarm', 'recovery']
#         assert severity in [None, "remind", "warning", "fatal"]  # p4 p3 p2
#         assert alarm_source in [None, 'zabbix', 'dedicated_line']
#         self.timestamp = timestamp
#         self.ip = ip
#         self.hostname = hostname
#         self.severity = severity
#         self.alarm_type = alarm_type
#         self.alarm_info = alarm_info
#         self.note = note
#         self.alarm_send = False
#         self.recovery = recovery
#         self.recovery_send = False
#         self.recovery_time = recovery_time
#         self.manager_ip = manager_ip  # for zabbix container.
#         self.manager_port = manager_port  # for zabbix container.
#         self.alarm_source = alarm_source
#         self.alarm_id = self._get_alarm_id()
#         self.last_send_time = None
#
#     def to_json(self):
#         ret_json = {}
#         attrs = dir(self)
#         for attr in attrs:
#             if str(attr).startswith('__'):
#                 continue
#             v = getattr(self, attr)
#             if isinstance(v, (str, int, float, bool, NoneType)):
#                 ret_json[attr] = v
#         return ret_json
#
#     @staticmethod
#     def json_to_obj(json_obj):
#         """
#
#         """
#         alarm = Alarm()
#         for k, v in json_obj.items():
#             if str(k).startswith('__'):
#                 continue
#             setattr(alarm, k, v)
#         alarm.alarm_id = alarm._get_alarm_id()
#         return alarm
#
#     def _get_alarm_id(self):
#         """
#         This function gets the alarm id.
#         Returns:
#
#         """
#         if self.alarm_info is not None:
#             content = f"{self.alarm_source}/{self.hostname}/{self.ip}/{self.alarm_info}/{self.alarm_type}"
#             return get_string_md5(content)
